package com.hedl.classroom.controller;


import com.hedl.classroom.base.exception.CommonResult;
import com.hedl.classroom.model.dto.BindTeachplanMediaDto;
import com.hedl.classroom.model.dto.SaveTeachplanDto;
import com.hedl.classroom.model.dto.TeachplanDto;
import com.hedl.classroom.model.po.Teachplan;
import com.hedl.classroom.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 课程计划管理相关接口
 */
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
@Slf4j
@RestController
public class TeachplanController {

    @Resource
    private TeachplanService teachplanService;

    @GetMapping("/teachplan/{courseId}/tree-nodes")
    @ApiOperation("查询课程计划")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "courseId",name = "课程id",required = true,dataType = "Long")
    })
    public List<TeachplanDto> getTreeNodes(@PathVariable("courseId") Long courseId){
        List<TeachplanDto> teachplanDtos = teachplanService.selectTreeNodes(courseId);
        return teachplanDtos;
    }

    @PostMapping("/teachplan")
    @ApiOperation("新增章节")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "saveTeachplanDto",value = "新增章节",required = true,dataType = "Object")
    })
    public void saveTeachplan(@RequestBody SaveTeachplanDto saveTeachplanDto){
        log.info("新增章节数据：{}",saveTeachplanDto);
        teachplanService.saveTeachplan(saveTeachplanDto);
    }

    @DeleteMapping("/teachplan/{id}")
    @ApiOperation("根据课程id删除课程计划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "课程id",required = true,dataType = "Long")
    })
    public CommonResult deleteTeachplan(@PathVariable("id") Long id){
        log.info("需要删除的id：{}",id);
        CommonResult commonResult = teachplanService.selectTeachplanByid(id);
        return commonResult;
    }

    @PostMapping("/teachplan/{moveType}/{id}")
    @ApiOperation("课程计划向上下移动")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "moveType",value = "判断是否上下移",required = true,dataType = "String"),
            @ApiImplicitParam(name = "id",value = "课程计划id",required = true,dataType = "Long")
    })
    public void moveup(@PathVariable("moveType") String moveType,@PathVariable("id") Long id){
        teachplanService.orderByTeachplan(moveType,id);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "删除指定媒资视频")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teachplanId",value = "课程id",required = true,dataType = "Long"),
            @ApiImplicitParam(name = "mediaId",value = "媒资id",required = true,dataType = "String")
    })
    @DeleteMapping("/teachplan/association/media/{teachplanId}/{mediaId}")
    public void deleteTeachplanMedia(@PathVariable("teachplanId") Long teachplanId,@PathVariable("mediaId") String mediaId){
        log.info("课程ID：{},媒资id:{}",teachplanId,mediaId);
        teachplanService.deleteTeachplanMedia(teachplanId,mediaId);
    }

    @ApiOperation("课程计划查询")
    @PostMapping("/teachplan/{teachplanId}")
    public Teachplan getTeachplan(@PathVariable("teachplanId") Long teachplanId){
        return teachplanService.getTeachplan(teachplanId);
    }

}